package com.admin.action.bookaction;

import com.admin.Action;
import com.admin.service.bookservice.BookServiceImpl;
import com.admin.service.bookservice.BookServiceInF;
import com.pojo.BooksBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 书籍的修改
 */
public class BookAlterAction extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out=response.getWriter();
        HttpSession session = request.getSession();
//        System.out.println(session.getAttribute("adminInfo"));
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }

        String bookName=request.getParameter("bookName");
        Long bookid= Long.valueOf(request.getParameter("bookid"));
        Double bookPrice= Double.valueOf(request.getParameter("bookPrice"));
        String bookAuthor=request.getParameter("bookAuthor");
        Double bookBorrowPrice= Double.valueOf(request.getParameter("bookBorrowPrice"));
        String bookPress=request.getParameter("bookPress");
        Long bookType= Long.valueOf(request.getParameter("bookTYpe"));
        Long bookStock= Long.valueOf(request.getParameter("bookStock"));
        String bookNumber=request.getParameter("bookNumber");

//        System.out.println(bookNumber+"-0-0"+bookNumber);
        BooksBean booksBean = new BooksBean();
        booksBean.setBookNumber(bookNumber);
        booksBean.setBookName(bookName);
        booksBean.setStock(bookStock);
        booksBean.setPress(bookPress);
        booksBean.setPrice(bookPrice);
        booksBean.setBookId(bookid);
        booksBean.setBorrowPrice(bookBorrowPrice);
        booksBean.setAuthor(bookAuthor);
        booksBean.setType(bookType);
        BookServiceInF service= new BookServiceImpl();
        service.alterBooks(booksBean);
//        System.out.println(service.alterBooks(booksBean));



    }
}
